var $ = require("../../utils/Ajax.js");
Page({
  data: {
    // 图片路径配置
    PictureUrl: getApp().PictureUrl,

    // 收货地址地址Id
    AddressId: 0,
    OrderInfor: null

  },

  onLoad: function (options) {
    var BuyInfor = JSON.parse(options.BuyInfor);
    console.log(BuyInfor)
    this.setData({
      OrderInfor: BuyInfor
    })
  },

  // 点击确认付款
  PaymentSubmit: function () {
    var that = this;
    $.Ajax("api/makeTeaOrder", "POST", {
      tid: that.data.OrderInfor.goods.id,
      num: 1,
      addressId: that.data.OrderInfor.address.id,
    }, function (res) {
      if(res.s){
        wx.requestPayment({
          timeStamp: res.d.config.timestamp,
          nonceStr: res.d.config.nonceStr,
          package: res.d.config.package,
          signType: res.d.config.signType,
          paySign: res.d.config.paySign,
          success: function (res) {
            wx.navigateTo({
              url: '../MyOrder/MyOrder',
            })
          },
          fail: function (res) {
            wx.showToast({
              title: "取消支付",
              icon: 'success',
              duration: 1500
            })
          }
        })
      }else{
        wx.showToast({
          title: res.m,
          icon: 'none',
          duration: 1500
        })
      }
    })
  }
})